package com.ruyuan.eshop.pay.remote;

import com.alibaba.csp.sentinel.annotation.SentinelResource;
import com.ruyuan.eshop.common.core.JsonResult;
import com.ruyuan.eshop.order.api.AfterSaleApi;
import com.ruyuan.eshop.order.domain.request.RefundCallbackRequest;
import com.ruyuan.eshop.pay.exception.PayBizException;
import com.ruyuan.eshop.pay.remote.fallback.AfterSaleRemoteFallback;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.stereotype.Component;

/**
 * 订单售后远程接口
 *
 * 儒猿课堂: http://www.ruyuan2020.com
 * @Author zhonghuashishan
 * @Remark 有问题直接联系客服VX: ruyuan-1111 ，源码-笔记-技术交流群
 * @Version 1.0
 **/
@Component
public class AfterSaleRemote {

    @DubboReference(version = "1.0.0")
    private AfterSaleApi afterSaleApi;

    /**
     * 取消订单支付退款回调
     */
    @SentinelResource(value = "AfterSaleRemote:refundCallback", fallbackClass = AfterSaleRemoteFallback.class, fallback = "refundCallbackFallback")
    public JsonResult<Boolean> refundCallback(RefundCallbackRequest payRefundCallbackRequest) {
        JsonResult<Boolean> jsonResult = afterSaleApi.refundCallback(payRefundCallbackRequest);
        if (!jsonResult.getSuccess()) {
            throw new PayBizException(jsonResult.getErrorCode(), jsonResult.getErrorMessage());
        }
        return jsonResult;
    }

}
